#ifndef FFMPEGFUN_H
#define FFMPEGFUN_H
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include"common.h"

void ShowMetaData(const AVDictionary *m);
void ShowAllStreams(AVFormatContext *fmt_ctx);
void ShowAllProgram(AVFormatContext *fmt_ctx);

typedef struct _FF_VIDEOINFO{
int idx;
AVStream *stream;
AVCodecContext*codec;
#if USE_FFMPEG_SWS
struct SwsContext *pSws;  
int length;
#endif
}FF_VIDEOINFO;
typedef struct _FF_AUDIOINFO{
int idx;
AVStream *stream;
AVCodecContext*codec;
#if USE_FFMPEG_SWR
struct SwrContext *pSwr;
int length;
#endif
}FF_AUDIOINFO;
int FindVideoCodec(AVFormatContext *fmt_ctx);
int FindAudioCodec(AVFormatContext *fmt_ctx);
int TryGetAudioCodec(FF_AUDIOINFO*audioinfo,AVFormatContext *fmt_ctx);
int TryGetVideoCodec(FF_VIDEOINFO*videoinfo,AVFormatContext *fmt_ctx);
int TryDecAudioPacket(FF_AUDIOINFO*audioinfo,AVPacket*packet,AVFrame*pFrame);
int TryDecVideoPacket(FF_VIDEOINFO*videoinfo,AVPacket*packet,AVFrame*pFrame);
int FF_DEC_Thread(void*data);

int InitFFMpeg(const char*filename);
void UnInitFFMpeg();
typedef struct _FF_STATUS{
int sample_rate; 
int samples;
int channels;
int width;
int height;
int running;
int hasvideo;
int hasaudio;
}FF_STATUS;
extern FF_STATUS g_ff_status;
//#define WINDOWS_WIDTH 640
//#define WINDOWS_HIGHT 480
//#define VIDEO_TYPE    AV_PIX_FMT_BGR24
typedef struct _DATAINFO{
uint8_t *data;
int length;
int width;
int height;
uint32_t timestamp;
struct _DATAINFO*Next;
}DATAINFO;

void InitSDLMutx();
void UnInitSDLMutx();
int  SDL_VIDEO_Thread(void*data);
void InitAudioThread(int sample_rate,uint16_t samples);
int  GetVideoPacketNum();
int  GetAudioPacketNum();
void PushVideoPacket(uint8_t *buffer,int width,int height,uint32_t timestamp);
void PushAudioPacket(uint8_t *buffer,int length,uint32_t timestamp);
DATAINFO*GetVideoPacket();
DATAINFO*GetAudioPacket();
//-1low 0normal 1fast
int IsVideoFastThenAudio();
void TestReadFrame();
#endif